﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConjureBivouac2012.Sprites;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ConjureBivouac2012.Object
{
    public class ShieldDeflecter: AbstractShield
    {
        public override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
            angle = 120;
            shieldDecreaseAmount = 1;
            shieldDecreaseDelay = 1;
            shieldMinValue = 20;
        }

        public override void Draw(SpriteBatch spriteBatch, Vector2 pos, float radius)
        {
            startingAngle = -(float)(startingAngle * 360 / (2 * Math.PI));
            startingAngle += angle / 2;
            if (startingAngle < 0)
                startingAngle += 360;
            else if (startingAngle >= 360)
                startingAngle -= 360;
            Primitive2D.DrawArc(spriteBatch, pos, radius, 90, 360 - startingAngle, angle, Color.White, 5);
        }

        public override bool IsHurt(Vector2 colliderPos)
        {
            float shieldangle = -(float)(startingAngle * 360 / (2 * Math.PI));
            shieldangle += angle / 2;
            colliderPos.Normalize();
            float enemyAngle = -(float)Math.Atan2(colliderPos.Y, colliderPos.X);
            enemyAngle = (float)(enemyAngle * 360 / (2 * Math.PI));
            if (enemyAngle < 0)
                enemyAngle += 360;
            else if (enemyAngle >= 360)
                enemyAngle -= 360;

            if (shieldangle - angle < 0)
            {
                if (enemyAngle <= shieldangle || enemyAngle >= 360 + (shieldangle - angle))
                    return false;
                else
                    return true;
            }
            else if (enemyAngle > shieldangle || enemyAngle < shieldangle - angle)
                return true;
            else
                return false;
        }
    }
}
